//
//  ZhuCustomCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/1.
//  Copyright © 2017年 金橙云. All rights reserved.
//

//区域筛选
#define Start_X 66  // 第一个按钮的X坐标
#define Start_Y 2// 第一个按钮的Y坐标
#define Width_Space 3//2个按钮之间的横间距
#define Height_Space 2 // 竖间距
#define Button_Height 39 // 高
#define Button_Width (DAN_WIDTH-60-3*4)/3 // 宽


#define DAN_WIDTH  ([UIScreen mainScreen].bounds.size.width)
#import "ZhuCustomCell.h"
#import "HouseModel.h"
#include "objc/runtime.h"

@implementation ZhuCustomCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        _valueDic = [NSMutableDictionary dictionary];
        _oneLab = [[UILabel alloc] init];
        _oneLab.backgroundColor = [UIColor whiteColor];
        _oneLab.text = @"14";
        _oneLab.textAlignment = NSTextAlignmentCenter;
        _oneLab.font = [UIFont systemFontOfSize:12];
        [self addSubview:_oneLab];
        [_oneLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 40));
            make.left.equalTo(self.mas_left).offset(2);
            make.top.equalTo(self.mas_top).offset(2);
            
        }];
        
        _houseArr = [[NSMutableArray alloc] init];
        _titArr = [[NSMutableArray alloc] init];
        
        
    }
    return self;
}

-(void)setupCustomTableViewCellWIthBtnArr:(NSMutableArray *)_arr withStatne:(NSMutableArray *)_stuse withShangLab:(NSMutableArray *)_shangArr model:(HouseModel *)allmodel
{
    /*
     
     [(ZhuCustomCell *)cell setupCustomTableViewCellWIthBtnArr:_changArr withStatne:mode.is_sale withShangLab:nil model:self.houModel];
     

     */
  
    // = _arr;
   // self.model = allmodel;
    
    
    for (int i = 0; i<_arr.count; i++)
    {
         DataModel2 *model = _arr[i];
        NSInteger index = i % 3;
        NSInteger page = i / 3;
        
        
        
        // 圆角按钮
        _nBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        _nBtn.backgroundColor = [UIColor whiteColor];
        _nBtn.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
        [_nBtn setTitleColor:[UIColor blackColor] forState:0];
        _nBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        _nBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    
        _nBtn.tag = [model.room_id  intValue];
   
        [_nBtn setTitle:model.room_num_sale forState:UIControlStateNormal];
        
        
        objc_setAssociatedObject(_nBtn, @"firstObject", _stuse[i], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
        [_nBtn addTarget:self action:@selector(houseBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_nBtn];
        
         NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
        if ([IDA isEqualToString:@"1"])
        {
            if ([_stuse[i] isEqualToString:@"0"])
            {
                _nBtn.backgroundColor = [UIColor whiteColor];
                [_nBtn setTitleColor:[UIColor blackColor] forState:0];
                
               
                //[_nBtn setUserInteractionEnabled:YES];
            }
            if ([_stuse[i] isEqualToString:@"2"])
            {
                _nBtn.backgroundColor = [UIColor colorWithHexString:@"#ff0000"];
                [_nBtn setTitleColor:[UIColor whiteColor] forState:0];
               
                [_nBtn setUserInteractionEnabled:NO];
            }
            if ([_stuse[i] isEqualToString:@"3"])
            {
                _nBtn.backgroundColor = [UIColor colorWithHexString:@"#009b42"];
               
                [_nBtn setTitleColor:[UIColor whiteColor] forState:0];
                [_nBtn setUserInteractionEnabled:NO];
            }
            if ([_stuse[i]  isEqualToString:@"10"])
            {
                _nBtn.backgroundColor = [UIColor colorWithHexString:@"#f703e5"];
             
                [_nBtn setTitleColor:[UIColor whiteColor] forState:0];
                [_nBtn setUserInteractionEnabled:NO];
            }
            if ([_stuse[i] isEqualToString:@"5"])
            {
                _nBtn.backgroundColor = [UIColor colorWithHexString:@"#00B8EC"];
                [_nBtn setUserInteractionEnabled:NO];
                [_nBtn setTitleColor:[UIColor whiteColor] forState:0];
                [_nBtn setUserInteractionEnabled:NO];
               
            }
         
        }
        
        else
        {
            if ([_stuse[i] isEqualToString:@"0"])
            {
                _nBtn.backgroundColor = [UIColor whiteColor];
                [_nBtn setTitleColor:[UIColor blackColor] forState:0];
                 NSLog(@"-----11111------%@",_stuse);
                //[_nBtn setUserInteractionEnabled:YES];
            }
            if ([_stuse[i] isEqualToString:@"2"])
            {
                _nBtn.backgroundColor = [UIColor colorWithHexString:@"#ff0000"];
                [_nBtn setTitleColor:[UIColor whiteColor] forState:0];
                  NSLog(@"-----2222221------%@",model.is_sale);
              
            }
            if ([_stuse[i] isEqualToString:@"3"])
            {
                _nBtn.backgroundColor = [UIColor colorWithHexString:@"#009b42"];
                
                [_nBtn setTitleColor:[UIColor whiteColor] forState:0];
                 NSLog(@"-----3333333------%@",model.is_sale);
            }
            if ([_stuse[i] isEqualToString:@"10"])
            {
                _nBtn.backgroundColor = [UIColor colorWithHexString:@"#f703e5"];
                
                [_nBtn setTitleColor:[UIColor whiteColor] forState:0];
                  NSLog(@"-----444444------%@",model.is_sale);
            }
            if ([_stuse[i]  isEqualToString:@"5"])
            {
                _nBtn.backgroundColor = [UIColor colorWithHexString:@"#00B8EC"];
                [_nBtn setUserInteractionEnabled:NO];
                [_nBtn setTitleColor:[UIColor whiteColor] forState:0];
                
                 NSLog(@"-----555555------%@",model.is_sale);
            }

        }
        
        
    }

   
    }
-(void)houseBtnClick:(UIButton *)btn
{

    NSInteger ttag = btn.tag;
   NSString *Tag = [NSString stringWithFormat:@"%ld",(long)ttag];//房间id
    NSLog(@"Tag===%@",Tag);

    id first = objc_getAssociatedObject(btn, @"firstObject");
    NSLog(@"first===%@",first);
    [_valueDic setObject:Tag forKey:@"B_TAG"];
    [_valueDic setObject:first forKey:@"B_SALE"];//是否已售状态
   // NSLog(@"----按钮的标题----%@",btn.titleLabel.text);
    
    
    
    //NSLog(@"-----按钮的状态---%@",_btnSale);

    [self.delegate houseBtnClick:_valueDic];

    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
